package behavior.memento;

public class MementoTest {

	public static void main(String[] args) {
		BackupData data1 = new BackupData("data1");
		BackupData data2 = new BackupData("data2");

		// 备份数据
		BackupCaretaker careTaker = new BackupCaretaker();
		careTaker.add(data1.saveToMemento());
		careTaker.add(data2.saveToMemento());

		// 开始修改数据
		System.out.println("修改前的数据为：" + data1.getData() + ";" + data2.getData());
		data1.setData("new data1");
		data2.setData("new data2");
		System.out.println("修改后的数据为：" + data1.getData() + ";" + data2.getData());

		// 开始还原数据
		System.out.println("修改数据出现异常需要还原回去");
		data1.restoreFromMemento(careTaker.get(0));
		data2.restoreFromMemento(careTaker.get(1));
		System.out.println("还原后的数据为：" + data1.getData() + ";" + data2.getData());
	}

}
